<include file='public/_meta'>
<title>车辆列表</title>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 车辆档案 <span class="c-gray en">&gt;</span> 车辆列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form method="post" action="{:url('index/Cars/index')}">
			<div class="text-c"> 添加日期：
				<input type="text" name="datemin" value="{$datemin}" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'datemax\')||\'%y-%M-%d\' }' })" id="datemin" class="input-text Wdate" style="width:100px;">
				-
				<input type="text" name="datemax" value="{$datemax}" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'datemin\') }',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:100px;">
				<input type="text" name="search" value="{$search_value}" class="input-text" style="width:250px" placeholder="车牌、车架、卡号、智能设备号..." id="search_inpute" >
				<span class="select-box" style="width:100px;">
					<select class="select" name="brand_id" id="brand_id">
                        <option value="">品牌类型</option>
                        <foreach $brand as $value>
                        <option value="{$value.id}" {$value['id']==$brand_id?'selected':''}>{$value.name}</option>
                    	</foreach>                        
                    </select>
				</span>
				<span class="select-box" style="width:100px;">
                    <select class="select" name="relevance" id="relevance" size="1">
                        <option value="">租赁类型</option>
                        <option value="1" {$relevance==1?'selected':''}>分时租赁</option>
                        <option value="2" {$relevance==2?'selected':''}>企业用车</option>
                        <option value="3" {$relevance==3?'selected':''}>共享用车</option>
                        <option value="4" {$relevance==4?'selected':''}>长租车辆</option>
                        <option value="5" {$relevance==5?'selected':''}>自测试用</option>
                        <option value="6" {$relevance==6?'selected':''}>上牌整备</option>
                        <option value="7" {$relevance==7?'selected':''}>整备待租</option>
                    </select>
                </span>
                <span class="select-box" style="width:100px;">
                    <select class="select" name="agency_id" id="agency_id">
                        <option value="">加盟商</option>
                        <foreach $agency as $value>
                        <option value="{$value.id}" {$value['id']==$agency_id?'selected':''}>{$value.name}</option>
                    	</foreach>
                        
                    </select>
                </span>
				<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>		
			</div>
		</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" onclick="product_add('添加车辆','{:url('index/cars/add')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加车辆</a></span>  <span class="ml-5"> <a class="btn btn-success radius" onclick="excel_data_add('excel导入','{:url('index/cars/excelToData')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> EXCEL导入</a></span> <span class="ml-5"> <a class="btn btn-warning radius" onclick="excel_data_out('导出excel','{:url('index/excell/cars')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe641;</i> 导出EXCEL</a></span> <span class="r">共有数据：<strong>{$number}</strong> 条</span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
				
					<th width="40">ID</th>
					<th width="">车牌号</th>
					<th width="">品牌名称</th>
					<th width="">车架号</th>
					<th width="">租赁类型</th>
					<th>加盟商</th>
					<th width="120">添加时间</th>
					<!-- <th width="60">发布状态</th> -->
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){

	$('.table-sort').dataTable({
		"aaSorting": [[ 0, "desc" ]],//默认第几个排序
		// "bStateSave": true,//状态保存
		 searching: false,
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,1,2,3,4,5,6,7]}// 制定列不参与排序
		],
		"bProcessing" : true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好  
        "bServerSide" : true,//服务器处理分页，默认是false，需要服务器处理，必须true  
        "ajax": {
		    "url": "{:url('index/Cars/index')}",
		    "type": "POST",
		    "data":{
		    	'datemin':$('#datemin').val(),
		    	'datemax':$('#datemax').val(),
		    	'search':$('#search_inpute').val(),
		    	'relevance':$('#relevance').val(),
		    	'agency_id':$('#agency_id').val(),
		    	'brand_id':$('#brand_id').val()

		    },
	  	},
	  	displayLength: 10,
	  	columns: [
        { data: 'car_id' },
        { data: 'car_sn' },
        { data: 'brand_name' },
        { data: 'car_unique_id' },
        { data: 'relevance' ,render:function(data, type, row, meta){
        	switch (data) {
		        case 1:
		        data = '分时租赁';     
		            break;
		        case 2:
		        data = '企业用车';     
		            break;
		        case 3:
		        data = '共享用车';     
		            break;
		        case 4:
		        data = '长租车辆';     
		            break;
		        case 5:
		        data = '自测试用';     
		            break;
		        case 6:
		        data = '上牌整备';     
		            break;
		        case 7:
		        data = '整备待租';     
		            break;    
		        default:
		        data = '暂无分类';   
		            break;
		    }
        	return data;

        }},
        { data: 'agency_name'},
    
        { data: 'create_time' },
        { className: "td-manage",data: '',render: function (data, type, row, meta) {
        							var str = '';
        							if(row['band_status']==0){
										str += '<a title="绑定车辆" href="javascript:;" onclick="product_start(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe603;</i></a>';
        							}else if(row['band_status']==1){
        								str += '<a title="解除绑定" href="javascript:;" onclick="product_stop(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6de;</i></a>';
        								
        							}

                                	str += '<a title="编辑" href="javascript:;" onclick="product_edit(';
	                                str += "'编辑',";
	                                str += "'{:url('index/Cars/edit')}?car_id="+row['car_id']+"'";
	                                str += ",'',550)\"";
	                                str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
	                                str += '<a title="删除" href="javascript:;" onclick="product_del(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
	                                
                                return str;
                                
                            }
        },

    	],
    	 
	});

});

/*导入表格数据*/
function excel_data_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*导出*/
function excel_data_out(title,url,w,h) {
	layer.confirm('<p class="c-warning">可以选择搜索条件导出</p>',function(index){
		// top.location.href = url;
		let datemin = $('#datemin').val();
    	let datemax = $('#datemax').val();
    	let search = $('#search_inpute').val();
    	let relevance = $('#relevance').val();
    	let agency_id = $('#agency_id').val();
    	let brand_id = $('#brand_id').val();

		window.location.href = url+'?'+'datemin='+datemin+'&datemax='+datemax+'&search='+search+'&relevance='+relevance+'&agency_id='+agency_id+'&brand_id'+brand_id;
		// layer_show(title,url,w,h);
	
			layer.msg('导出成功,正在下载', {icon: 1});
			
	
	});

}
/*产品-添加*/
function product_add(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*产品-查看*/
function product_show(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*产品-审核*/
function product_shenhe(obj,id){
	layer.confirm('审核文章？', {
		btn: ['通过','不通过'], 
		shade: false
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
		$(obj).remove();
		layer.msg('已发布', {icon:6,time:1000});
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
		$(obj).remove();
    	layer.msg('未通过', {icon:5,time:1000});
	});	
}
/*车辆解绑*/
function product_stop(obj,id){
	layer.confirm('解除绑定',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url('index/Cars/unBandCars')}',
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.result == 0){

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_start(this,'+id+')" href="javascript:;" title="绑定车辆"><i class="Hui-iconfont">&#xe603;</i></a>');
					$(obj).remove();
					layer.msg('已解绑!',{icon: 5,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});	
		
		
	});
}

/*车辆绑定*/
function product_start(obj,id){
	layer.confirm('绑定车辆',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url('index/Cars/bandCars')}',
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.result == 0){
					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_stop(this,'+id+')" href="javascript:;" title="解除绑定"><i class="Hui-iconfont">&#xe6de;</i></a>');
					$(obj).remove();
					layer.msg('已绑定!',{icon: 6,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});

		
	});
}

/*产品-申请上线*/
function product_shenqing(obj,id){
	$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
	$(obj).parents("tr").find(".td-manage").html("");
	layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}

/*产品-编辑*/
function product_edit(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*产品-删除*/
function product_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: "{:url('index/Cars/delete')}",
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.status == 0){

				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script>
</body>
</html>